'use strict';

/**
 * @param {Egg.Application} app - egg application
 */
module.exports = app => {
  const { router, controller, middleware } = app;
  const { sign, auth, rbac } = middleware;

  // 是否开启API签名验证
  const enableRSAChecker = false;

  // 注意中间件的执行顺序
  const checks = enableRSAChecker ? [sign(), auth(), rbac()] : [auth()];

  // 上传
  router.post('/api/upload/file', controller.upload.file);

  router.post('/api/staff/login', controller.staff.login);
  router.post('/api/member/login', controller.member.login);
  router.post('/api/customer/login', controller.customer.login);
  router.post('/api/user/login', controller.user.login);

  // banner
  router.get('/api/banner/list', controller.banner.allList);
  router.resources('banner', '/api/banner', controller.banner);
  // 商品分类
  router.get('/api/category/list', controller.category.allList);
  router.get('/api/category/list2', controller.category.allList2);
  router.resources('category', '/api/category', controller.category);
  // 商品
  router.get('/api/goods/list', controller.goods.allList);
  router.resources('goods', '/api/goods', controller.goods);
  // 商品订单
  router.post('/api/order/confirm', controller.order.confirmOrder);
  router.post('/api/order/accept', controller.order.staffAccept);
  router.get('/api/order/staff', controller.order.staffList)
  router.get('/api/order/list', controller.order.allList);
  router.resources('order', '/api/order', controller.order);
  router.resources('order', '/api/orderDetail', controller.orderDetail);
  // 会员
  router.get('/api/member/list', controller.member.allList);
  router.resources('member', '/api/member', controller.member);
  // 地址
  router.get('/api/address/list', controller.address.allList);
  router.post('/api/address/updateStatus', controller.address.updateStatus);
  router.resources('address', '/api/address', controller.address);
  // 收藏
  router.get('/api/collect/list', controller.collect.allList);
  router.resources('collect', '/api/collect', controller.collect);
  // 足迹
  router.get('/api/footer/list', controller.footer.allList);
  router.resources('footer', '/api/footer', controller.footer);
  // 角色
  router.get('/api/role/list', controller.role.allList);
  router.resources('role', '/api/role', controller.role);
  // 用户
  router.get('/api/user/list', controller.user.allList);
  router.resources('user', '/api/user', controller.user);
  // 店铺
  router.get('/api/shop/list', controller.shop.allList);
  router.resources('shop', '/api/shop', controller.shop);

  // 发票
  router.get('/api/invoice/list', controller.invoice.allList);
  router.resources('invoice', '/api/invoice', controller.invoice);
  // 反馈
    router.get('/api/feedback/list', controller.feedback.allList);
    router.resources('feedback', '/api/feedback', controller.feedback);
    // 充值
  router.get('/api/recharge/list', controller.recharge.allList);
    router.resources('recharge', '/api/recharge', controller.recharge);
    // 员工
    router.get('/api/staff/list', controller.staff.allList);
    router.resources('staff', '/api/staff', controller.staff);
    // 企业
    router.get('/api/company/list', controller.company.allList);
    router.resources('company', '/api/company', controller.company);
    // 客户
    router.get('/api/customer/list', controller.customer.allList);
    router.resources('customer', '/api/customer', controller.customer);

  /**
   * 骑手
   */
    // 骑手
    router.post('/api/staff/login', controller.staff.login);
    router.get('/api/staff/list', controller.staff.allList);
    router.resources('staff', '/api/staff', controller.staff);
    // 骑手余额
    router.get('/api/balance/list', controller.staffBalance.allList);
    router.resources('balance', '/api/balance', controller.staffBalance);
};
